using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using ViewOnCore.HostContract;
using ViewOnCore.HostContract.Settings;
using SettingsAddIn.Properties;

namespace UI.SettingsPanel
{

    public partial class SettingsAutoUpdateControl : System.Windows.Controls.UserControl, ISettingPanel
    {

        #region Constructor

        public SettingsAutoUpdateControl()
        {
            InitializeComponent();

            Reset();

            btnUpdate.Click += new RoutedEventHandler(btnUpdate_Click);
        }

        #endregion

        #region Properties

        public string Title
        {
            get
            {
                return SettingsAddIn.Properties.Globalization.SettingsPart_AutoUpdate;
            }
        }

        #endregion

        #region Button : Update

        void btnUpdate_Click(object sender, RoutedEventArgs e)
        {
            Host.AutoUpdateService.StartAutoUpdateApplication();
        }

        #endregion

        #region ISettingPanel Members

        public void Reset()
        {
            chkCheckUpdateAtStartup.IsChecked = Host.AutoUpdateService.CheckUpdateAtStartup;
            txtVersion.Text = Host.AutoUpdateService.Version.Major + "." + Host.AutoUpdateService.Version.Minor;
            txtLastCheck.Text = Host.AutoUpdateService.LastCheckingDate.ToShortDateString();
            for (int index = 1; index <= 60; index++)
                cboCheckDays.Items.Add(index);
            cboCheckDays.SelectedValue = Host.AutoUpdateService.AutoUpdateEvery;
        }

        public void Apply()
        {
            Host.AutoUpdateService.CheckUpdateAtStartup = (chkCheckUpdateAtStartup.IsChecked == true);
            Host.AutoUpdateService.AutoUpdateEvery = (int)cboCheckDays.SelectedValue;
        }

        public void Cancel()
        {
            Reset();
        }

        #endregion

    }
}